package com.channel.temperature.collect.ui.adapter

import android.util.Log
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.channel.temperature.collect.R
import com.channel.temperature.collect.app.util.MyUtil
import com.channel.temperature.collect.data.response.OfflineBean


class TemperatureAdapter :
    BaseQuickAdapter<OfflineBean, BaseViewHolder>(R.layout.item_temperature) {

    override fun convert(holder: BaseViewHolder, item: OfflineBean) {
        var time = item.time + 8 * 3600

//        holder.setText(R.id.time, "" + MyUtil.DateToStr(Date(time * 1000)))
        var result = item.dataResult

        Log.e("convert", "convert  列表值 " + result)
        holder.setText(
            R.id.batteryELect,
            "电池电压:" + result.substring(8, 12).toInt(16) + "mV"
        )
        holder.setText(
            R.id.gx1, "GX1温度：" + (result.substring(12, 16).toInt(16).toFloat()) / 100.0f + "℃"
        )
        holder.setText(
            R.id.gx2, "GX2温度：" + (result.substring(16, 20).toInt(16).toFloat()) / 100.0f + "℃"
        )
        holder.setText(
            R.id.pt1,
            "PT电压1:" + MyUtil.bytes2Float(MyUtil.hex2Bytes(result.substring(20, 28)))
                .toFloat() + "uV"
        )
        holder.setText(
            R.id.pt2,
            "PT电压2:" + MyUtil.bytes2Float(MyUtil.hex2Bytes(result.substring(28, 36)))
                .toFloat() + "uV"
        )
        holder.setText(
            R.id.pressure1,
            "压力电压1:" + (MyUtil.bytes2Float(MyUtil.hex2Bytes(result.substring(36, 44)))
                .toFloat()) + "uV"
        )
        holder.setText(
            R.id.pressure2,
            "压力电压2:" + (MyUtil.bytes2Float(MyUtil.hex2Bytes(result.substring(44, 52)))
                .toFloat()) + "uV"
        )

        holder.setText(
            R.id.jzElect,
            "基准电压:" + (MyUtil.bytes2Float(MyUtil.hex2Bytes(result.substring(52, 60)))
                .toFloat()) + "uV"
        )
    }

}